<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Calculator</title>
</head>
<body>
    <table>
        <tr>
            <td><img src="20240807115258.png" width="62" height="64"></td>
            <td colspan="3">购物简易计算器</td>
        </tr>
        <tr>
            <td>第一个数：</td>
            <td colspan="3">
                <input type="text" id="numID1">
            </td>
        </tr>
        <tr>
            <td>第二个数：</td>
            <td colspan="3">
                <input type="text" id="numID2">
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" value="+" onclick="calculator('+')">
            </td>
            <td>
                <input type="button" value="-" onclick="calculator('-')">
            </td>
            <td>
                <input type="button" value="*" onclick="cal('*')">
            </td>
            <td>
                <input type="button" value="/" onclick="cal('/')">
            </td>
        </tr>
        <tr>
            <td>计算结果：</td>
            <td colspan="3">
                <input type="text" id="resultID">
            </td>
        </tr>
    </table>

    <script>
        function calculator(type) {
            var num1 = document.getElementById("numID1").value;
            var num2 = document.getElementById("numID2").value;
            var result = eval(parseInt(num1) + type + parseInt(num2));
            var resultObj = document.getElementById("resultID");
            resultObj.value = result;
        }

        function cal(type) {
            var num1 = document.getElementById("numID1").value;
            var num2 = document.getElementById("numID2").value;
            switch (type) {
                case '+':
                    var result = parseInt(num1) + parseInt(num2);
                    break
                case '-':
                    var result = parseInt(num1) - parseInt(num2);
                    break
                case '*':
                    var result = parseInt(num1) * parseInt(num2);
                    break
                case '/':
                    var result = parseInt(num1) / parseInt(num2);
                    break
            }
            var resultObj = document.getElementById("resultID");
            resultObj.value = result;
        }

        function Addition() {
            var num1 = document.getElementById("numID1").value;
            var num2 = document.getElementById("numID2").value;
            var result = parseInt(num1) + parseInt(num2);
            var resultObj = document.getElementById("resultID");
            resultObj.value = result;
        }

        function Subtraction() {
            var num1 = document.getElementById("numID1").value;
            var num2 = document.getElementById("numID2").value;
            var result = parseInt(num1) - parseInt(num2);
            var resultObj = document.getElementById("resultID");
            resultObj.value = result;
        }

        function Multiplication() {
            var num1 = document.getElementById("numID1").value;
            var num2 = document.getElementById("numID2").value;
            var result = parseInt(num1) * parseInt(num2);
            var resultObj = document.getElementById("resultID");
            resultObj.value = result;
        }

        function Division() {
            var num1 = document.getElementById("numID1").value;
            var num2 = document.getElementById("numID2").value;
            var result = parseInt(num1) / parseInt(num2);
            var resultObj = document.getElementById("resultID");
            resultObj.value = result;
        }
    </script>
</body>
</html>